//
//  ImageTextTableViewCell.m
//  段子
//
//  Created by dllo on 16/6/22.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ImageTextTableViewCell.h"
#import "imageViewTextFieldView.h"
#import "GetRowHeightTools.h"
#import "ContentModel.h"

@interface ImageTextTableViewCell ()


@property(nonatomic, retain)UIImageView *coCoimageView;

@property(nonatomic, retain)UILabel *textCellLabel;
@property(nonatomic, retain)imageViewTextFieldView *praise;
@property(nonatomic, retain)imageViewTextFieldView *critical;
@property(nonatomic, retain)imageViewTextFieldView *comment;
@property(nonatomic, retain)UIButton *forward;

@end


@implementation ImageTextTableViewCell

- (void)dealloc
{
    [_coCoimageView release];
    [_textCellLabel release];
    [_model release];
    [_praise release];
    [_critical release];
    [_comment release];
    [_forward release];
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.textCellLabel = [[UILabel alloc]init];
        [self.contentView addSubview:_textCellLabel];
        [_textCellLabel release];
        
        
        self.coCoimageView = [[UIImageView alloc]init];
        [self.contentView addSubview:_coCoimageView];
        [_coCoimageView release];
        
        
        self.praise = [[imageViewTextFieldView alloc]init];
        [self.contentView addSubview:_praise];
        [_praise release];
        
        self.critical = [[imageViewTextFieldView alloc]init];
        [self.contentView addSubview:_critical];
        [_critical release];
        
        self.comment = [[imageViewTextFieldView alloc]init];
        [self.contentView addSubview:_comment];
        [_comment release];
        
        self.forward = [[UIButton alloc]init];
        [self.contentView addSubview:_forward];
        [_forward release];
        
        
    }
    return self;
    
}


-(void)layoutSubviews{
    
    [super layoutSubviews];
    
    // label行数
    CGFloat labelHeight = [GetRowHeightTools heightWith:self.model.digest];
    self.textCellLabel.frame = CGRectMake(0, 0, self.contentView.bounds.size.width, labelHeight);
    self.textCellLabel.numberOfLines = 0;
//    self.textCellLabel.text = self.model.digest;

    
    // 图片高度
    
    CGFloat imageHeight = [GetRowHeightTools imageHeightWith:self.model.imgsrc];
    self.coCoimageView.frame = CGRectMake(0, _textCellLabel.frame.size.height + 10, CGRectGetWidth(self.contentView.bounds), imageHeight + 10);
    // 这里暂时没做数据处理
//    self.coCoimageView.image = [UIImage imageNamed:self.model.imgsrc];
    self.coCoimageView.backgroundColor = [UIColor redColor];
    
    
    
    
    
    
    // 按赞次数
    self.praise.frame = CGRectMake(10, _textCellLabel.frame.size.height + _coCoimageView.frame.size.height+ 10, 100, 40);
    self.praise.handImageView.image = [UIImage imageNamed:@"priase.png"];
    
    self.praise.handImageView.backgroundColor = [UIColor blackColor];
    
    // 不攒次数
    self.critical.frame = CGRectMake(_praise.frame.size.width + 5, _praise.frame.origin.y, _praise.frame.size.width, _praise.frame.size.height);
        self.critical.handImageView.image = [UIImage imageNamed:@"critical.png"];
    
    self.critical.handImageView.backgroundColor = [UIColor redColor];
    
    // 评论次数
    self.comment.frame = CGRectMake(_critical.frame.size.width + 80, _critical.frame.origin.y, _critical.frame.size.width, _critical.frame.size.height);
    self.comment.handImageView.image = [UIImage imageNamed:@"comment.png"];
    self.comment.handImageView.backgroundColor = [UIColor yellowColor];
}

-(void)setModel:(ContentModel *)model{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    self.comment.countTextField.text = [NSString stringWithFormat:@"%ld",self.model.replyCount];
    self.critical.countTextField.text =[NSString stringWithFormat:@"%ld", self.model.downTimes];
    self.praise.countTextField.text =[NSString stringWithFormat:@"%ld", self.model.upTimes];

    NSURL *url = [NSURL URLWithString:self.model.imgsrc];
    
    NSData *data = [NSData dataWithContentsOfURL:url];
    
    
    UIImage *image = [UIImage imageWithData:data];

    self.textCellLabel.text = self.model.digest;
    self.coCoimageView.image = image;
}

















@end
